var app = getApp()
Component({
  properties: {
    goods_info: {
      type: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    radio: "",
    type: "lawyer",
    listData: []
  },
  observers: {
    "goods_info": function (list) {
      console.log(list)
      if (list.length !== 0) {
        let _arr = [];
        if (list.length == 1) {
          _arr = list;
        } else {
          _arr = list.filter(item => {
            if(item.status == null){
              return item
            }
            if(item.service_data.type == "tel"  && item.status == 1){
              return item
            }else if(item.service_data.type == "line"){
              return item
            }
          });
        }
        this.triggerEvent("lawyerChange", _arr[0]);
        this.setData({
          listData: list,
          radio: _arr[0].id
        })
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    link(e) {
      let id = e.currentTarget.dataset.id,
        type = e.currentTarget.dataset.type;
      wx.navigateTo({
        url: `/packageI/lawyerPlatform/detail/detail?id=${id}&type_name=${type}`
      })
    },
    onChange(event) {
      this.data.listData.forEach((item, i) => {
        if (item.id == event.detail && item.status == 0 && item.service_data.type == 'tel') {
          item.disabled = true;
          this.setData({
            ['listData[' + i + '].disabled']: true
          })
          app.tips("律师休息，暂不能购买电话咨询服务")
        }
      })
      this.setData({
        radio: event.detail,
      });
      let result = this.data.listData.filter(item => item.id == event.detail);
      this.triggerEvent("lawyerChange", result[0]);
    },
  }
});
